// app.js
import http from './utils/request/index';
import store from './utils/store/$store';
import nav from './utils/root/nav';
import authPage from './utils/root/pages';
import utils from './utils/util';
import verify from './utils/verify';
App({
    authPage,
    utils,
    $verify: verify,
    ...store,
    http,
    nav,
    // 计算安全区域
    getSecurityZone() {
        let res = wx.getWindowInfo();
        let bottom = (res.safeArea.bottom - res.safeArea.height + 10);
        return bottom;
    },
    onLaunch() {
        // 展示本地存储能力
        const logs = wx.getStorageSync('logs') || []
        logs.unshift(Date.now())
        wx.setStorageSync('logs', logs)
    }, // 设置全局事件
    getViewInfo() {
        // 获取手机系统信息
        let systemInfo = wx.getWindowInfo();

        // 屏幕顶部状态栏高度
        let statusBarHeight = Number(systemInfo.statusBarHeight);

        // 获取胶囊区信息
        let menu = wx.getMenuButtonBoundingClientRect();

        // 胶囊区高度
        let menuHeight = menu.height;

        // 胶囊区距离屏幕顶部的距离
        let menuTop = menu.top;

        // 屏幕顶部导航栏高度
        let navBarHeight = menu.height + (menu.top - statusBarHeight) * 2;

        // 屏幕顶部状态栏加导航栏高度
        let navStatusBarHeight = statusBarHeight + menu.height + (menu.top - statusBarHeight) * 2;
        // 屏幕底部安全区高度
        // css 可用 env(safe-area-inset-bottom) 或 constant(safe-area-inset-bottom)
        let iosSABottom = 0; //
        if (systemInfo.safeArea) {
            iosSABottom = Number(systemInfo.screenHeight - systemInfo.safeArea.bottom);
        }
        let maxHeight = systemInfo.windowHeight - (navStatusBarHeight + statusBarHeight - 2);
        this.globalData.view = {
            iosSABottom: iosSABottom,
            navBarHeight: navBarHeight,
            maxHeight: maxHeight,
            menuWidth: menu.width,
            menu: menu,
            statusBarHeight: statusBarHeight,
            titleTopDistance: statusBarHeight - 2,
            navStatusBarHeight: navStatusBarHeight
        };
        // console.log("获取手机系统信息", systemInfo);
        // console.log("获取胶囊区信息", menu);
        // console.log("胶囊区高度", menuHeight);
        // console.log("胶囊区距离屏幕顶部的距离", menuTop);
        // console.log("屏幕顶部状态栏高度", statusBarHeight);
        // console.log("屏幕顶部导航栏高度", navBarHeight);
        // console.log("屏幕顶部状态栏加导航栏高度", navStatusBarHeight);
        // console.log("屏幕底部安全区高度", iosSABottom);
        // console.log("最大可视化高度", maxHeight ) ;
    },
    // 设置全局窗口位置
    onLoad(options) {},
    onShow() {
        this.getViewInfo()
    },
    globalData: {
        view: {},
        userInfo: null
    }
})